package com.example;

import org.junit.Test;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class SetTest {

    @Test
    public void test01() {
        Set<Integer> set1 = new HashSet<>();
        set1.add(1);
        set1.add(1); // 舍弃
        set1.add(2);
        set1.add(5);
        set1.add(3);
        System.out.println(set1);
    }

    @Test
    public void test02() {
        Set<User> set1 = new HashSet<>();
        set1.add(new User(1, "张三")); // hashCode:10
        set1.add(new User(1, "王五")); // hashCode:10
        set1.add(new User(2, "李四")); // hashCode:10
        System.out.println(set1);
        // Set集合没有索引的概念
        // set1.get(0)
    }
}
